package svc

import (
	"fmt"
	"time"

	"mall/service/mqueue/scheduler/internal/config"

	"github.com/hibiken/asynq"
	"github.com/zeromicro/go-zero/core/service"
)

func newScheduler(c config.Config) *asynq.Scheduler {
	location, _ := time.LoadLocation("Asia/Shanghai")
	if c.Mode != service.ProMode { // 测试环境
		return asynq.NewScheduler(
			asynq.RedisClientOpt{
				Addr:     c.BizRedis.Host,
				Password: c.BizRedis.Pass,
			},
			&asynq.SchedulerOpts{
				Location: location,
				EnqueueErrorHandler: func(task *asynq.Task, opts []asynq.Option, err error) {
					fmt.Printf("Scheduler EnqueueErrorHandler <<<<<<<===>>>>> err : %+v , task : %+v", err, task)
				},
			},
		)
	}

	return asynq.NewScheduler(
		asynq.RedisClusterClientOpt{
			Addrs:    []string{c.BizRedis.Host},
			Password: c.BizRedis.Pass,
		},
		&asynq.SchedulerOpts{
			Location: location,
			EnqueueErrorHandler: func(task *asynq.Task, opts []asynq.Option, err error) {
				fmt.Printf("Scheduler EnqueueErrorHandler <<<<<<<===>>>>> err : %+v , task : %+v", err, task)
			},
		},
	)
}
